package net.zjitc.servlet;

import net.zjitc.domain.Product;
import net.zjitc.service.ProductService;
import net.zjitc.service.impl.ProductServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import java.util.Map;

/**
 * @Author admin
 * @Date 2019/2/27 13:57
 */
@WebServlet(name = "UpdateProductServlet",urlPatterns = "/updateProduct")
public class UpdateProductServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        Product product = new Product();
        String pid = request.getParameter("pid");
        Map<String, String[]> parameterMap = request.getParameterMap();
        try {
            BeanUtils.populate(product,parameterMap);
            ProductService service = new ProductServiceImpl();
            service.update(product,pid);
        }  catch (Exception e) {
            e.printStackTrace();
        }
        request.getRequestDispatcher("/findDetail").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
